﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace NJL.WebUsers
{
    public class BaseUserControl : System.Web.UI.UserControl
    {
        /// <summary>
        /// 网站编号
        /// </summary>
        public string WEBSITE_CODE
        {
            get { return System.Configuration.ConfigurationManager.AppSettings["WebSiteCode"]; }
        }
        /// <summary>
        /// 网站编号
        /// </summary>
        public string WEBSITE_AREA_NAME
        {
            get { return System.Configuration.ConfigurationManager.AppSettings["WebSiteAreaName"]; }
        }

        /// <summary>
        /// 网站名称
        /// </summary>
        public string WEBSITE_NAME 
        {
            get { return System.Configuration.ConfigurationManager.AppSettings["WebSiteName"]; }
        }

        /// <summary>
        /// 网站域名
        /// </summary>
        public string WEBSITE_DOMAIN
        {
            get { return System.Configuration.ConfigurationManager.AppSettings["WebSiteDomain"]; }
        }

        /// <summary>
        /// 网站图片域名
        /// </summary>
        public string WEBSITE_IMAGE_DOMAIN
        {
            get { return System.Configuration.ConfigurationManager.AppSettings["WebSiteImageDomain"]; }
        }

        /// <summary>
        /// 网站用户登录域名
        /// </summary>
        public string WEBSITE_USRE_DOMAIN
        {
            get { return System.Configuration.ConfigurationManager.AppSettings["WebSiteUserDomain"]; }
        }

        /// <summary>
        /// 网站默认城市编号
        /// </summary>
        public string WEBSITE_DEFAULT_CITY_CODE
        {
            get { return System.Configuration.ConfigurationManager.AppSettings["DefaultCityCode"]; }
        }

        /// <summary>
        /// 网站默认城市名称
        /// </summary>
        public string WEBSITE_DEFAULT_CITY_NAME
        {
            get { return System.Configuration.ConfigurationManager.AppSettings["DefaultCityName"]; }
        }

        /// <summary>
        /// 当前网站城市编号
        /// </summary>
        public string WEBSITE_FOCUS_CITY_CODE
        {
            get
            {
                if (Request.QueryString["cc"] != null)
                {
                    Model.NJL_CS_AREA model = new BLL.NJL_CS_AREA().GetModel(WEBSITE_CODE, Request.QueryString["cc"].ToLower());
                    if (null != model)
                    {
                        return model.AREA_CODE;
                    }
                    else
                    {
                        return "";
                    }
                }
                else
                {
                    return "";
                }
            }
        }

        /// <summary>
        /// 当前网站城市名称
        /// </summary>
        public string WEBSITE_FOCUS_CITY_NAME
        {
            get
            {
                if (WEBSITE_FOCUS_CITY_CODE != "")
                {
                    return new BLL.NJL_CS_AREA().GetModel(WEBSITE_FOCUS_CITY_CODE).AREA_NAME;
                }
                else
                {
                    return "全省";
                }
            }
        }

        /// <summary>
        /// 当前网站城市名称拼音
        /// </summary>
        public string WEBSITE_FOCUS_CITY_NAME_PINYIN
        {
            get
            {
                if (WEBSITE_FOCUS_CITY_CODE != "")
                {
                    return new BLL.NJL_CS_AREA().GetModel(WEBSITE_FOCUS_CITY_CODE).AREA_NAME_PINYIN;
                }
                else
                {
                    return "";
                }
            }
        }

        /// <summary>
        /// 获取当前网站的基本信息
        /// </summary>
        public Model.NJL_SYS_BASE WEBSITE_SYS_BASE
        {
            get { return new BLL.NJL_SYS_BASE().GetModelByCache(WEBSITE_CODE); }
        }

        public BaseUserControl()
        {
        }
        /// <summary>
        /// 用户编号
        /// </summary>
        public string UserId
        {
            get
            {
                if (Session["userid"] != null)
                {
                    return Session["userid"].ToString();
                }
                else
                {
                    return "";
                }
            }
        }
        /// <summary>
        /// 用户名
        /// </summary>
        public string UserName
        {
            get
            {
                if (Session["username"] != null)
                {
                    return Session["username"].ToString();
                }
                else
                {
                    return "";
                }
            }

        }
        /// <summary>
        /// 网站编号
        /// </summary>
        public string WebSiteCode
        {
            get
            {
                return WEBSITE_CODE;
            }
        }
        /// <summary>
        /// 用户类型
        /// </summary>
        public string UserType
        {
            get
            {
                if (Session["usertype"] != null)
                {
                    return Session["usertype"].ToString();
                }
                else
                {
                    return "";
                }
            }
        }
        #region 后台图片上传、读取、删除公共处理方法

        /// <summary>
        /// 通过图片编号获取图片URL路径
        /// </summary>
        /// <param name="ImageCode"></param>
        /// <returns></returns>
        public string GetImageUrl(string ImageCode)
        {
            BLL.NJL_IMAGE bll = new BLL.NJL_IMAGE();

            Model.NJL_IMAGE model = bll.GetModel(ImageCode);

            if (model != null)
            {
                return System.Configuration.ConfigurationManager.AppSettings["WebSiteImageDomain"] + model.IMAGE_URL_PATH + model.IMAGE_NAME + model.IMAGE_TYPE;
            }
            else
            {
                return "";
            }
        }

        /// <summary>
        /// 通过图片编号获取图片URL路径
        /// </summary>
        /// <param name="ImageCode"></param>
        /// <returns></returns>
        public static string GetImageUrl(string ImageCode, string SizeType)
        {
            BLL.NJL_IMAGE bll = new BLL.NJL_IMAGE();

            Model.NJL_IMAGE model = bll.GetModel(ImageCode);

            if (model != null)
            {
                return System.Configuration.ConfigurationManager.AppSettings["WebSiteImageDomain"] + "/?st=" + SizeType.Trim() + "&id=" + model.ID;
            }
            else
            {
                return "";
            }
        }

        #endregion

        #region 根据城市编号获取城市拼音
        public string GetAreaNamePinYin(string AreaCode)
        {
            Model.NJL_CS_AREA model = new BLL.NJL_CS_AREA().GetModelByCache(AreaCode);

            if (null != model)
            {
                return model.AREA_NAME_PINYIN;
            }
            else
            {
                return "";
            }
        }
        #endregion
        #region 根据城市编号获取城市名称
        public string GetAreaName(string AreaCode)
        {
            Model.NJL_CS_AREA model = new BLL.NJL_CS_AREA().GetModelByCache(AreaCode);

            if (null != model)
            {
                return model.AREA_NAME;
            }
            else
            {
                return "";
            }
        }
        #endregion

        #region 通过UserID获取商铺ID
        public string GetCompanyIDByUserID(string UserID)
        {
            Model.NJL_COMPANY model = new BLL.NJL_COMPANY().GetCompanyByUserIDModel(UserId);

            if (model != null)
            {
                return model.ID;
            }
            else
            {
                return "";
            }
        }
        #endregion

        #region 订票付款方式
        public string GetBookPayType(string TypeCode)
        {
            Model.NJL_CS_BOOK_PAY model = new BLL.NJL_CS_BOOK_PAY().GetModelByCache(TypeCode);

            if (null != model)
            {
                return model.TYPE_NAME;
            }
            else
            {
                return "";
            }
        }
        #endregion
    }
}